package com.mj.app.health.net;

import com.mj.app.common_util.net.HttpConnection;
import com.mj.app.health.net.post.LoginPost;
import com.mj.app.health.net.post.MainPost;
import com.mj.app.health.net.post.RecordPost;
import com.mj.app.health.net.post.RegistorPost;
import com.mj.app.health.net.post.ServiceDetailPost;
import com.mj.app.health.net.post.ServicePost;
import com.mj.app.health.net.post.SignPost;
import com.mj.app.health.net.post.UserRefreshPost;
import com.mj.app.health.net.response.LoginResponse;
import com.mj.app.health.net.response.MainResponse;
import com.mj.app.health.net.response.RecordResponse;
import com.mj.app.health.net.response.RegistorResponse;
import com.mj.app.health.net.response.ServiceDetailResponse;
import com.mj.app.health.net.response.ServiceResponse;
import com.mj.app.health.net.response.SignResponse;
import com.mj.app.health.net.response.UserRefreshResponse;

/**
 * ========================================
 * *
 * title: HttpGo
 * description: 接口
 * *
 * Created by David Hogan on 2018/3/5.
 * ========================================
 */

public class HttpGo {

//    private static String baseUrl = "http://172.28.59.111:8080/maventest"; // 改成自己的地址
    private static String baseUrl = "http://192.168.1.101:8080/maventest";

    /**
     * 登录
     * @param userName
     * @param userPwd
     */
    public static void login(String userName, String userPwd, HttpListener<LoginResponse> listener){
        LoginPost loginPost = new LoginPost(userName, userPwd);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/user/api/userLogin", loginPost, listener, LoginResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     * 注册user/userList
     * @param userName
     * @param userPwd
     * @param listener
     */
    public static void registor(String userName, String userPwd, HttpListener<RegistorResponse> listener){
        RegistorPost registorPost = new RegistorPost(userName, userPwd);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/user/api/userRegist", registorPost, listener, RegistorResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     * 刷新用户信息
     * @param userId
     * @param listener
     */
    public static void refreshUser(String userId, HttpListener<UserRefreshResponse> listener){
        UserRefreshPost refreshPost = new UserRefreshPost(userId);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/user/api/userRefresh", refreshPost, listener, UserRefreshResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     * 首页加载
     * @param userId
     * @param fromCount
     * @param toCount
     * @param listener
     */
    public static void loadMain(String userId, int fromCount, int toCount, HttpListener<MainResponse> listener){
        MainPost mainPost = new MainPost(userId, fromCount, toCount);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/ad/api/loadMain", mainPost, listener, MainResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     *  签到
     * @param userId
     * @param listener
     */
    public static void sign(String userId, HttpListener<SignResponse> listener){
        SignPost signPost = new SignPost(userId);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/user/api/userSign", signPost, listener, SignResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     * 服务列表
     * @param userId
     * @param type
     * @param listener
     */
    public static void loadService(String userId, int fromCount, int toCount, int type, HttpListener<ServiceResponse> listener){
        ServicePost servicePost = new ServicePost(userId,fromCount, toCount, type);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/paper/api/paperList", servicePost, listener, ServiceResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     * 获取服务内容详情
     * @param detailId
     * @param listener
     */
    public static void serviceDetail(String detailId, HttpListener<ServiceDetailResponse> listener){
        ServiceDetailPost detailPost = new ServiceDetailPost(detailId);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/paper/api/paperDetail", detailPost, listener, ServiceDetailResponse.class);
        httpConnection.doJsonPost();
    }

    /**
     * 增加运动记录
     * @param title
     * @param des
     * @param duration
     * @param listener
     */
    public static void insertRecord(String title, String des, String duration, HttpListener<RecordResponse> listener){
        RecordPost post = new RecordPost(title, des, duration);
        HttpConnection httpConnection = new HttpConnection(baseUrl +"/record/api/insertRecord", post, listener, RecordResponse.class);
        httpConnection.doJsonPost();
    }
}
